package cn.zhaoyuening.crm.web.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import cn.zhaoyuening.crm.domain.CrmStaff;

public class LoginInterceptor extends MethodFilterInterceptor{

	@Override
	public String doIntercept(ActionInvocation invocation) throws Exception {
		Object object = ActionContext.getContext().getSession().get("loginStaff");
		if (object!=null && object instanceof CrmStaff) {
			//处于登录状态
			return invocation.invoke();
		}
		if(invocation.getAction() instanceof ActionSupport){
			ActionSupport actionSupport = (ActionSupport) invocation.getAction();
			actionSupport.addFieldError("", "请登录");
		}
		/**友好信息 end*/
		
		// 没有登录，需要登录
		return "login";
	}

}
